<?php
    session_start();
    require_once '../includes/runtime/lib/Propel.php';
    Propel::init("../includes/build/conf/easylib-conf.php");
    set_include_path("../includes/build/classes" . PATH_SEPARATOR . get_include_path());
    $id=$_POST['id'];
    $abonnement=  TabAbonnementQuery::create()->filterByIdAbonnement($id)->findOne();
    $abonne = TabAbonneQuery::create()->filterByEmail($_SESSION["user_login"])->findOne();
    $licence=new TabLicence();
    $licence->setFkAbonne($abonne->getIdAbonne());
    $licence->setFkAbonnement($id);
    $d1=date("Y-m-d H:i:s");
    $licence->setDateDebut($d1);
    if($abonnement->getDuree()==365)
       $d2=strtotime(date("Y-m-d H:i:s", strtotime($d1)) . " +1 year");
    else if($abonnement->getDuree()==7)
       $d2=strtotime(date("Y-m-d H:i:s", strtotime($d1)) . " +7 day");
    else
        $d2=strtotime(date("Y-m-d H:i:s", strtotime($d1)) . " +1 day");
    $licence->setDateFin($d2);
    $licence->save();
?>
